package com.goldenbean.test;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@ManagedBean
@SessionScoped
public class User {

	private String userName;
	private String password;
	private String tel;
	private String address;
	
	
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String login(){
		if("zhangsan".equals(this.getUserName()) && "123456".equals(this.password)){
			
			FacesContext fc = FacesContext.getCurrentInstance();
			HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
			HttpSession session = request.getSession(true);
			
			User bean = new User();
			bean.setUserName("zhangsan");
			bean.setAddress("address");
			
			session.setAttribute("loginUser", bean);
			
			return "/page/ajax";
		}
		return "/page/fail";
	}
	
}
